package com.example.plane;


import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.plane.GameView.GameView;

public class MenuActivity extends AppCompatActivity {
        public static int game_state;
    public static int PLAY_START=1;
    public static int CONTIINUE_START=2;
    public static int ABOUT_GAME=4;
    public static int SETTING_GAME=3;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        Button buttonplay = (Button) findViewById(R.id.buttonplay);
        Button buttoncontinue = (Button) findViewById(R.id.buttoncountinue);
        Button buttonsetting = (Button) findViewById(R.id.buttonsteting);
        Button buttonabout = (Button) findViewById(R.id.buttonabout);
        MainActivity.mediaPlayer[0].seekTo(0);
        MainActivity.mediaPlayer[0].start();
        buttonplay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 MainActivity.mediaPlayer[0].pause();
                 game_state=PLAY_START;
//                 MainActivity.mediaPlayer_menu.release();
                AlertDialog.Builder builder=new AlertDialog.Builder(MenuActivity.this);
                builder.setTitle("开始游戏");
                builder.setMessage("要开始新的游戏吗？");
                builder.setPositiveButton("是的", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //应该保存的数据
                        Intent intent = new Intent(MenuActivity.this, GameActivity.class);//打开下一个活动
                        startActivity(intent);

                    }
                });
                builder.setNegativeButton("不是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

            }
        });
        buttoncontinue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.mediaPlayer[0].pause();
                game_state=CONTIINUE_START;
//                 MainActivity.mediaPlayer_menu.release();
                Intent intent = new Intent(MenuActivity.this, GameActivity.class);//打开下一个活动
                startActivity(intent);
                finish();
            }
        });
        buttonsetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MenuActivity.this, SettingActivity.class);//打开下一个活动
                startActivity(intent);
                finish();
            }
        });
        buttonabout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MenuActivity.this, AboutActivity.class);//打开下一个活动
                startActivity(intent);
                finish();
            }
        });
//        constraintLayout.setOnTouchListener(new View.OnTouchListener() {//对该布局进行触屏监控
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                if(event.getAction()==MotionEvent.ACTION_UP)//判断事件类型是否为按下
//                {
//                    MainActivity.soundPool.stop(1);
//                    Intent intent = new Intent(MenuActivity.this,GameActivity.class);//打开下一个活动
//                    startActivity(intent);
//                }
//                return true;
//            }
//        });

    }

    public void onBackPressed() {
       MainActivity.mediaPlayer[0].pause();
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("退出？");
            builder.setMessage("你确定要退出？");
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
//                    MenuActivity.super.onBackPressed();//注释掉这行,back键不退出activity
//                    finish();
                    System.exit(0);
                }
            });
            builder.setNegativeButton("再玩会儿", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                MainActivity.mediaPlayer[0].start();
                }
            });
           builder.show();

    }
}
